<%@update_id = 'sections_list'%>
<script type="text/javascript">
 // <![CDATA[
    layout = eval(<%=@current_layout%>);
    titles = eval(<%=@article_titles%>);
    if (!layout) 
      var layout = new Array();
    //]]>
</script>

    <%=collapsable_panel(self.render(:partial => "new_section_panel", 
                                 :locals => {:update_id=>@update_id} ),
                                 '+ Add a new section','create_section_panel', 
                                 "display:none")%>
                                 

    <%
# FIXME: Find a way for the helper to accept the :parameters property, whe need to send the array in JSON to the server

link_to_remote("Change layout" ,
               :update => 'show_here',
               :url => { :action => :set_issue_layout , :id=>session[:issue].id.to_s},
               :method =>  'post',
               :before => "pars = 'layout='+layout.toJSONString()",
               :parameters => "pars")
    
# mean while theres a version by hand it works but is pretty ugly                
    %>



    
    <h2>Front page</h2>
    
    <ul id="layout_reciever" >

    </ul>

        <a href="#" onclick="<%= " pars = 'layout='+layout.toJSONString() ; new Ajax.Updater('', '/edit/set_issue_layout/" + session[:issue].id.to_s + "', {method:'post', parameters:pars,asynchronous:true, evalScripts:true,onComplete: showLayoutResponse}); return false;"-%>">
        <button> Save front page</button>
        </a>
        |
        <a href="#" onclick="<%= "layout = []; pars = 'layout='+layout.toJSONString() ; new Ajax.Updater('', '/edit/set_issue_layout/" + session[:issue].id.to_s + "', {method:'post', parameters:pars,asynchronous:true, evalScripts:true, onComplete: showLayoutResponse });  $('layout_reciever').innerHTML = ''; return false;"-%>">
        <button>Clear front page</button>
        </a>           
    
        <script type="text/javascript">
 // <![CDATA[

        update_layout(layout, $('layout_reciever'))
 
 // ]]>
     </script>

    <div id= <%= @update_id %> >
        <ul >
          <%= render :partial => 'sections', :collection => @sections %>
        </ul>
     </div>                             
     
 <%= 
   drop_receiving_element "layout_reciever",

  :hoverclass => "layout_reciever_hover",
  :onDrop => " function (element) {  layout = addToLayout(element, layout); new Insertion.Bottom($('layout_reciever'), '<li>'+element.innerHTML+'</li>') }",
  :accept => "dragable_articles"

%>

<script type="text/javascript">
 // <![CDATA[
        Sortable.create("layout_reciever",{dropOnEmpty:true,containment:["layout_reciever"],constraint:false});

 // ]]>
 </script>

 <div id="show_here" >
</div>